<template>
  <van-cell class="article-item" @click="go">
    <template #title>
      <div class="head">
        <img
          :src="item.avatar"
          alt=""
        />
        <div class="con">
          <p class="title van-ellipsis">{{item.stem}}</p>
          <p class="other">{{item.creator}} | {{item.createdAt}}</p>
        </div>
      </div>
    </template>

    <template #label>
      <div class="body van-multi-ellipsis--l2" v-html="item.content">
       <!-- {{item.content}} -->
      </div>
      <div class="foot">点赞 {{item.creator}} | 浏览 {{item.views}}</div>
    </template>
  </van-cell>
</template>

<script>

export default {
  name: 'HmItem',
  props: ['item'],

  methods: {
    go () {
      // 需求：点击路由跳转之后去详情的路由

      // 1 路由跳转 路由规则里面起个名字
      // 跳转到名字为 detail 的页面 并且携带参数 id 去
      this.$router.push({
        name: 'detail', // 是名字不是路径 所以不带 /
        // 2 带上每个数据id
        params: {
          id: this.item.id
        }
      })
    }
  }
}
</script>

<style lang = 'less' scoped>
.article-item {
  .head {
    display: flex;
    img {
      width: 40px;
      height: 40px;
      border-radius: 50%;
      overflow: hidden;
    }
    .con {
      flex: 1;
      overflow: hidden;
      padding-left: 10px;
      p {
        margin: 0;
        line-height: 1.5;
        &.title {
          width: 280px;
        }
        &.other {
          font-size: 10px;
          color: #999;
        }
      }
    }
  }
  .body {
    font-size: 14px;
    color: #666;
    line-height: 1.6;
    margin-top: 10px;
  }
  .foot {
    font-size: 12px;
    color: #999;
    margin-top: 10px;
  }
}
</style>
